package com.guli.mall.serviceBase.config;
/*
 * @Author 罗
 * @date 2020/10/16 - 3:33 下午
 */

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
@Slf4j
@ConditionalOnClass(RedissonClient.class)
public class RedissonConfig {

    /**
     * 配置redisson单节点模式
     * */
    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson(RedisProperties redisProperties){

        Config config = new Config();
        /**
         * 要标注协议
         * */
        config.useSingleServer()
                .setAddress("redis://192.168.137.1:30011")
                .setDatabase(redisProperties.getDatabase()); // 信号量、锁之类的数据就存放在当前微服务的redis所操作的库中



        log.info("正在配置 Redisson");
        return Redisson.create(config);
    }
}
